|
|
|
|
|
|
|
To make the differences in intensity between different polygons noticeable, you also need to select kdist carefully. You need to make (rmin + kdist) reasonably sized compared with the differences in the distances from the polygons to the light source. |
|
|
|
|
|
|
|
|
If kdist is very small, the difference between (rmin + kdist) and (rmax + kdist) is relatively large. In that case, the intensity at polygons further from the light source is very small, and those polygons are too dark. |
|
|
|
|
|
|
|
|
On the other hand, if kdist is very large, the difference between (rmin + kdist) and (rmax + kdist) is relatively small. In that case, the intensity at polygons far from the light source is almost the same as at those that are closer. This makes it difficult to notice the differences in the intensities. |
|
|
|
|
|
|
|
|
Often you can get good results by making the intensity drop by roughly 50 percent across the scene. To do that, you need to satisfy the equation: |
|
|
|
 |
|
|
|
|
(rmin + kdist) / (rmax + kdist) = 0.5 |
|
|
|
 |
|
|
|
|
kdist = rmax - 2 * rmin |
|
|
|
|
|
|
|
|
To calculate color values with the distance term, the SurfaceColor function must know the values of kdist, rmin, and the distance between a polygon and a light source. Because the distance terms depend on the position of the light source, these values should be properties of the light source objects, not the scene as a whole or of the objects in the scene. With these extra terms, the LightSource class has the following declarations: |
|
|
|
 |
|
|
|
|
Option Explicit
Public X As Single
Public Y As Single
Public Z As Single
Public Ir As Single
Public Ig As Single
Public Ib As Single
Public Kdist As Single
Public Rmin As Single |
|
|
|
|
|
|
|
|
The ScaleIntensityForDepth subroutine shown in the following code sets the values of Kdist and Rmin for a light source. The Solids collection contains the Solid3d objects in the scene. The solid class used by this program provides a GetRminRmax routine that sets the minimum and maximum distances from the light source to the solid. |
|
|
|
 |
|
|
|
|
' Set this light source's Kdist and Rmin values. Private Sub ScaleIntensityForDepth(ByVal light As LightSource)
Dim solid As Solid3d
Dim Rmin As Single
Dim Rmax As Single |
|
|
|
|
|